﻿using HelperFromTheSkeleton.Model.RequestModels;

namespace HelperFromTheSkeleton.Model.PageModel
{
    /// <summary>
    /// 分页结果模型
    /// </summary>
    public class PageResultModel
    {
        /// <summary>
        /// 页数
        /// </summary>
        public int PageIndex { get; set; }

        /// <summary>
        /// 分页大小
        /// </summary>
        public int PageSize { get; set; }

        /// <summary>
        /// 总页数
        /// </summary>
        public int TotalPages { get; set; }

        /// <summary>
        /// 数据量
        /// </summary>
        public int DataCount { get; set; }
    }

    /// <summary>
    /// 结果模型
    /// </summary>
    /// <typeparam name="T"></typeparam>
    public class PageResultModel<T> : ResultModel
    {

        public List<T> Data { get; set; } = new List<T>();

        public PageResultModel PageData { get; set; } = new PageResultModel { DataCount = 0, PageIndex = 1, PageSize = 0, TotalPages = 0 };

        /// <summary>
        /// 成功
        /// </summary>
        /// <param name="data"></param>
        /// <param name="message"></param>
        /// <returns></returns>
        public  static PageResultModel<T> Succeed(List<T> data, PageResultModel page, string message)
        {
            var result = new PageResultModel<T>
            {
                Message = message,
                IsSucceed = true,
                Data = data,
                PageData = page
            };
            return result;
        }

        /// <summary>
        /// 失败
        /// </summary>
        /// <param name="message"></param>
        /// <returns></returns>
        public static new PageResultModel<T> Fall(string message)
        {
            var result = new PageResultModel<T>
            {
                Message = message,
                IsSucceed = false,
                Data = new List<T>(),
                PageData = new PageResultModel { DataCount = 0, PageIndex = 1, PageSize = 0, TotalPages = 0 }
            };
            return result;
        }
    }
}
